//
//  PresentModalHelper.m
//  OfficeBook
//
//  Created by 朱 琳 on 15/10/3.
//  Copyright (c) 2015年 sunny. All rights reserved.
//

#import "PresentModalHelper.h"
#import "ZFModalTransitionAnimator.h"

@implementation PresentModalHelper

+(void)presentModal:(UIViewController*)sourceController toController:(UIViewController*)controller {
     if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
         controller.providesPresentationContextTransitionStyle = YES;
         controller.definesPresentationContext = YES;
         [controller setModalPresentationStyle:UIModalPresentationOverCurrentContext];
     
         [sourceController presentViewController:controller animated:NO completion:nil];
     }
     else {
         sourceController.view.window.rootViewController.modalPresentationStyle = UIModalPresentationCurrentContext;
         [sourceController presentViewController:controller animated:NO completion:nil];
         sourceController.view.window.rootViewController.modalPresentationStyle = UIModalPresentationFullScreen;
     }
}

+(void) presentModalWithAnimation:(UIViewController*)sourceController toController:(UIViewController*)controller
                        direction:(ZFModalTransitonDirection)direction dragable:(BOOL)dragable {
    
    ZFModalTransitionAnimator *animator = [[ZFModalTransitionAnimator alloc] init];
    animator = [[ZFModalTransitionAnimator alloc] initWithModalViewController:controller];
    animator.dragable = dragable;
    animator.bounces = NO;
    animator.behindViewAlpha = 0.5f;
    animator.behindViewScale = 0.5f;
    animator.direction = direction;
    
    controller.transitioningDelegate = animator;
    [self presentModal:sourceController toController:controller];
}

@end
